package com.gonsin.gview.model.form;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.gonsin.gview.model.GButtonModel;
import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.gview.model.GBoardModel;
import com.gonsin.gview.model.data.GDataModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel("表单的描述")
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GFormBoardModel extends GBoardModel {

    @ApiModelProperty("页面类型")
    private String boardType = "form";

    @ApiModelProperty("表单拥有的项")
    private List<GFormItemModel> formItems;

    @ApiModelProperty("确认按钮的信息")
    private GButtonModel okButton;

    @ApiModelProperty("取消按钮的信息")
    private GButtonModel cancelButton;

    @ApiModelProperty("表单的数据源信息")
    private GDataModel data;


    @Override
    public GBoardModel tClone() {
        GFormBoardModel model = new GFormBoardModel();
        BeanUtil.copyProperties(this, model, CopyOptions.create().setIgnoreNullValue(true));
        if(formItems != null){
            model.formItems = new ArrayList<>();
            for(GFormItemModel f : formItems){
                model.formItems.add(f.tClone());
            }
        }
        if(okButton != null){
            model.okButton = okButton.tClone();
        }
        if(cancelButton != null){
            model.cancelButton = cancelButton.tClone();
        }
        model.data = data;
        return model;
    }
}
